cmake_minimum_required(VERSION 3.20)

project(CMake_testing)

add_executable(add main.cpp)

# 启用测试
enable_testing()
# 测试1
add_test(NAME test_1 COMMAND add 1 3)

# 测试2 无参数
add_test(NAME test_2 COMMAND add)
# 设置测试2属性 正则匹配结果
set_tests_properties(test_2 PROPERTIES PASS_REGULAR_EXPRESSION "Usage:.*")

# 测试3 无参数
add_test(NAME test_3 COMMAND add 3 7)
# 设置测试3属性 正则匹配结果
set_tests_properties(test_3 PROPERTIES PASS_REGULAR_EXPRESSION "10")

# 使用函数添加更多测试
function(do_test id a  b result)
    add_test(NAME test_${id} COMMAND add ${a} ${b})
    set_tests_properties(test_${id} PROPERTIES PASS_REGULAR_EXPRESSION "${result}")
endfunction()

do_test(4 5 9 14)
do_test(5 4 4 8)
do_test(6 2 6 8)
do_test(7 -5 -10 -15)
do_test(8 "" "" "Usage:")